<template>
  <el-row type="flex" justify="space-between" align="middle" style="height:40px; width:100%">
    <!-- 两个内容 -->
    <el-col>{{ nodeData.name }}</el-col>
    <el-row type="flex" justify="end">
      <!-- 两个内容 -->
      <el-col>{{ nodeData.manager }}</el-col>
      <el-col>
        <!-- 下拉菜单 element -->
        <el-dropdown>
          <span>
            操作<i class="el-icon-arrow-down" />
          </span>
          <!-- 下拉菜单 -->
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="addDepts">添加子部门</el-dropdown-item>
            <el-dropdown-item
              v-if="!isCompany"
              @click.native="editDepts"
            >编辑子部门</el-dropdown-item>
            <el-dropdown-item v-if="!isCompany" @click.native="delDepts">删除子部门</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
    </el-row>
  </el-row>
</template>
<script>
import { delDepts } from '@/api/department'
export default {
  props: {
    nodeData: {
      type: Object,
      required: true
    },
    isCompany: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    addDepts() {
      console.log('添加按钮被点击')
      this.$emit('addDepts', this.nodeData)
    },
    editDepts() {
      console.log('编辑按钮被点击')
      this.$emit('editDepts', this.nodeData)
    },
    async delDepts() {
      // 二次询问请求
      await this.$confirm('是否确认删除')
      // 发请求
      await delDepts(this.nodeData.id)
      // 请求成功
      this.$message.success('删除成功')
      // 更新页面
      this.$emit('reloadPage')
    }
  }
}
</script>
<style lang="">

</style>
